/**************************************************************************
 *         Copyright(c) 2007 by Sunplus mMedia  Technology Co., Ltd.       *
 *                                                                         *
 *  This software is copyrighted by and is the property of Sunplus mMedia  *
 *  Technology Co., Ltd. All rights are reserved by Sunplus mMedia Techno- *
 *  logy Co., Ltd. This software may only be used in accordance with the   *
 *  corresponding license agreement. Any unauthorized use, duplication,    *
 *  distribution, or disclosure of this software is expressly forbidden.   *
 *                                                                         *
 *  This Copyright notice "M U S T" not be removed or modified without     *
 *  prior written consent of Sunplus mMedia Technology  Co., Ltd.          *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd. reserves the right to modify this  *
 *  software without notice.                                               *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd.                                    *
 *  19-1, Innovation First Road, Science-Based Industrial Park,            *
 *  Hsin-Chu, Taiwan, R.O.C.                                               *
 *                                                                         *
 **************************************************************************/
#include "general.h"
#include "os_msg.h"
#include "key_scan.h"

#include "sp1k_disp_api.h"
#include "sp1k_pb_api.h"

#include "app_still_play.h"
#include "app_ui_osd.h"
#include "app_ui_power.h"
#include "app_battery.h"

/**************************************************************************
 *                      G L O B A L    C O N S T A N T                    *
 **************************************************************************/
#define SP1K_PAN_STEP	32
/**************************************************************************
 *                         G L O B A L    D A T A                         *
 **************************************************************************/


/**************************************************************************
 *               F U N C T I O N    D E C L A R A T I O N S               *
 **************************************************************************/


/**************************************************************************
 *                 E X T E R N A L    R E F E R E N C E S                 *
 **************************************************************************/
 extern UINT16 pbZoomCurLog ;
//-----------------------------------------------------------------------------
//appPanShow
//-----------------------------------------------------------------------------

void appPanShow(UINT8 msg)
{
	UINT16 newFact, pbZoomFact;
//	powerBatLv_t batlv;
	
	switch (msg) {
		case SP1K_MSG_STATE_INIT:
            pbZoomFact = 10000/pbZoomCurLog;    //xian ++ 20081208, #30690
            sp1kPbDZoomFactorSet(pbZoomFact);
            uiUpdateOSDPvZoom(pbZoomFact); 
			break;
    	case SP1K_MSG_KEY_PRESS_S1:
			break;
    	case SP1K_MSG_KEY_PRESS_S2:
			break;
    	case SP1K_MSG_KEY_PRESS_MENU:
			//no break here
		case SP1K_MSG_KEY_PRESS_PB:
			sp1kPbDZoomFactorSet(100);
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
			break;
    	case SP1K_MSG_KEY_PRESS_UP:
			break;
		case SP1K_MSG_KEY_RELEASE_UP:
		case SP1K_MSG_KEY_REPEATE_UP:
			sp1kPbImgPanSet(0, 0 - SP1K_PAN_STEP);
			break;
	    	case SP1K_MSG_KEY_PRESS_DOWN:
			break;
		case SP1K_MSG_KEY_RELEASE_DOWN:
		case SP1K_MSG_KEY_REPEATE_DOWN:
			sp1kPbImgPanSet(0, SP1K_PAN_STEP);
			break;
	    	case SP1K_MSG_KEY_PRESS_LEFT:
			break;
		case SP1K_MSG_KEY_RELEASE_LEFT:
		case SP1K_MSG_KEY_REPEATE_LEFT:
			sp1kPbImgPanSet(0 - SP1K_PAN_STEP, 0);
			break;
	    	case SP1K_MSG_KEY_PRESS_RIGHT:
			break;
		case SP1K_MSG_KEY_RELEASE_RIGHT:
		case SP1K_MSG_KEY_REPEATE_RIGHT:
			sp1kPbImgPanSet(SP1K_PAN_STEP, 0);
			break;
	    	case SP1K_MSG_KEY_PRESS_OK:
			break;
		case SP1K_MSG_KEY_PRESS_DISP:
			break;
		case SP1K_MSG_KEY_PRESS_TELE:
		case SP1K_MSG_KEY_REPEATE_TELE: 
			if (!sp1kPbFileCntGet()) {
				break;
			}
			//printf("up\n");
			//add for debug zoom error for avi@2008-03-07 begin
			if(pbFile.wType==SP1K_PB_FILE_TYPE_JPG)
				//add for debug zoom error for avi@2008-03-07 end
				pbZoomCurLog -= PLAY_ZOOM_logStep;
						
			if (pbZoomCurLog > PLAY_MAX_ZOOM_LOG)
				pbZoomCurLog = PLAY_MAX_ZOOM_LOG;
			
			newFact = 10000/pbZoomCurLog;
			if(newFact <= PLAY_MAX_ZOOM_FACT) {
				pbZoomFact = newFact;
			}
			else {
				pbZoomCurLog = PLAY_MIN_ZOOM_LOG;
				pbZoomFact = PLAY_MAX_ZOOM_FACT;
				return;
			}
			printf("fac:%d\n",pbZoomFact);
			sp1kPbDZoomFactorSet(pbZoomFact);
			uiUpdateOSDPvZoom(pbZoomFact); 
			break;
			
		case SP1K_MSG_KEY_PRESS_WIDE:
		case SP1K_MSG_KEY_REPEATE_WIDE:
			if (!sp1kPbFileCntGet()) {
				break;
			}
			//printf("down\n");
			//add for debug zoom error for avi@2008-03-07 begin
			//add for debug zoom error for avi@2008-03-07 end
			if(pbFile.wType==SP1K_PB_FILE_TYPE_JPG)
			pbZoomCurLog += PLAY_ZOOM_logStep;
						
			if (pbZoomCurLog < PLAY_MIN_ZOOM_LOG)
				pbZoomCurLog = PLAY_MIN_ZOOM_LOG;
			
			newFact = 10000/pbZoomCurLog;
			
			if(newFact >= PLAY_MIN_ZOOM_FACT ) {
				pbZoomFact = newFact;
			}
			else {
				pbZoomCurLog = PLAY_MAX_ZOOM_LOG; 
				pbZoomFact = PLAY_MIN_ZOOM_FACT;
				osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
				break;
			}
			printf("fac:%d\n",pbZoomFact);
			sp1kPbDZoomFactorSet(pbZoomFact);
			uiUpdateOSDPvZoom(pbZoomFact);//lryy modify

            if(pbZoomCurLog == PLAY_MAX_ZOOM_LOG){//xian ++ 20081208, #30690
				osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
            }
			//printf("dzf = %u\n", dzmFacTbl[pbFile.dzFactor]); 			
			//printf("tele\n");
			break;

	    	case SP1K_MSG_CARD_PLUG_IN:
			break;
	    	case SP1K_MSG_CARD_PLUG_OUT:
			break;
	    	case SP1K_MSG_USB_PLUG_IN:
			break;
	    	case SP1K_MSG_USB_PLUG_OUT:
			break;
	    	case SP1K_MSG_TV_PLUG_IN:
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
			osMsgPost(SP1K_MSG_TV_PLUG_IN);
			break;
	    	case SP1K_MSG_TV_PLUG_OUT:
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
			osMsgPost(SP1K_MSG_TV_PLUG_OUT);
			break;
		case SP1K_MSG_BAT_LV_UPDATE:
			uiUpdateBatteryLevel();
			appBattStsHandle();
			break;
		case SP1K_MSG_BAT_EMPTY:
			uiUpdateOSDBatEmpty();
			osMsgPost(SP1K_MSG_POWER_OFF);
			sp1kBtnDisableAll();//ready to power off, disable all button!
			break;

		case SP1K_MSG_POWER_OFF:
		case SP1K_MSG_KEY_PRESS_POWER:
			appPowerOffProc();
			break;
	    	default:
			//printf("Unknown message:%d\n", (UINT16)msg);
			break;
	}
}

